Floating Wave Scenario Analysis


In [ ]:
%matplotlib inline

In [ ]:
from IPython.display import display, HTML

In [ ]:
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (14.0, 8.0)

In [ ]:
import numpy as np
from datetime import datetime

In [ ]:
from dtocean_core import start_logging
from dtocean_core.core import Core
from dtocean_core.menu import DataMenu, ModuleMenu, ProjectMenu, ThemeMenu
from dtocean_core.pipeline import Tree, _get_connector
from dtocean_core.extensions import StrategyManager

In [ ]:
# Bring up the logger
start_logging()

In [ ]:
def html_list(x):
    message = "<ul>"
    for name in x:
        message += "<li>{}</li>".format(name)
    message += "</ul>"
    return message
def html_dict(x):
    message = "<ul>"
    for name, status in x.iteritems():
        message += "<li>{}: <b>{}</b></li>".format(name, status)
    message += "</ul>"
    return message
def html_variable(core, project, variable):
    value = variable.get_value(core, project)
    metadata = variable.get_metadata(core)
    name = metadata.title
    units = metadata.units
    message = "<b>{}:</b> {}".format(name, value)
    if units:
        message += " ({})".format(units[0])
    return message

Create the core, menus and pipeline tree

The core object carrys all the system information and is operated on by the other classes


In [ ]:
new_core = Core()
project_menu = ProjectMenu()
module_menu = ModuleMenu()
theme_menu = ThemeMenu()
data_menu = DataMenu()
pipe_tree = Tree()

Create a new project and tree


In [ ]:
project_title = "DTOcean"  
new_project = project_menu.new_project(new_core, project_title)

Set the device type


In [ ]:
options_branch = pipe_tree.get_branch(new_core, new_project, "System Type Selection")
variable_id = "device.system_type"
my_var = options_branch.get_input_variable(new_core, new_project, variable_id)
my_var.set_raw_interface(new_core, "Wave Floating")
my_var.read(new_core, new_project)

Initiate the pipeline

This step will be important when the database is incorporated into the system as it will effect the operation of the pipeline.


In [ ]:
project_menu.initiate_pipeline(new_core, new_project)

Discover available modules


In [ ]:
names = module_menu.get_available(new_core, new_project)
message = html_list(names)
HTML(message)

Activate some modules

Note that the order of activation is important and that we can't deactivate yet!


In [ ]:
module_menu.activate(new_core, new_project, 'Hydrodynamics')
module_menu.activate(new_core, new_project, 'Electrical Sub-Systems')
module_menu.activate(new_core, new_project, 'Mooring and Foundations')

Activate the Economics and Reliability themes


In [ ]:
names = theme_menu.get_available(new_core, new_project)
message = html_list(names)
HTML(message)

In [ ]:
theme_menu.activate(new_core, new_project, "Economics")

In [ ]:
# Here we are expecting Hydrodynamics
assert _get_connector(new_project, "modules").get_current_interface_name(new_core, new_project) == "Hydrodynamics"

In [ ]:
from aneris.utilities.analysis import get_variable_network, count_atomic_variables

In [ ]:
req_inputs, opt_inputs, outputs, req_inter, opt_inter = get_variable_network(new_core.control,
                                                                             new_project.get_pool(),
                                                                             new_project.get_simulation(),
                                                                             "modules")

In [ ]:
req_inputs[req_inputs.Type=="Shared"].reset_index()

In [ ]:
shared_req_inputs = req_inputs[req_inputs.Type=="Shared"]
len(shared_req_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(shared_req_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
opt_inputs[opt_inputs.Type=="Shared"].reset_index()

In [ ]:
shared_opt_inputs = opt_inputs[opt_inputs.Type=="Shared"]
len(shared_opt_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(shared_opt_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
req_inter

In [ ]:
len(req_inter["Identifier"].unique())

In [ ]:
count_atomic_variables(req_inter["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
opt_inter

In [ ]:
len(opt_inter["Identifier"].unique())

In [ ]:
count_atomic_variables(opt_inter["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
hyrdo_req_inputs = req_inputs.loc[req_inputs['Interface'] == 'Hydrodynamics']
len(hyrdo_req_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(hyrdo_req_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
hyrdo_opt_inputs = opt_inputs.loc[opt_inputs['Interface'] == 'Hydrodynamics']
len(hyrdo_opt_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(hyrdo_opt_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
electro_req_inputs = req_inputs.loc[req_inputs['Interface'] == 'Electrical Sub-Systems']
len(electro_req_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(electro_req_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
electro_opt_inputs = opt_inputs.loc[opt_inputs['Interface'] == 'Electrical Sub-Systems']
len(electro_opt_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(electro_opt_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
moorings_req_inputs = req_inputs.loc[req_inputs['Interface'] == 'Mooring and Foundations']
len(moorings_req_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(moorings_req_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
moorings_opt_inputs = opt_inputs.loc[opt_inputs['Interface'] == 'Mooring and Foundations']
len(moorings_opt_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(moorings_opt_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]:
total_req_inputs = req_inputs.loc[req_inputs['Interface'] != 'Shared']
len(total_req_inputs["Identifier"].unique())

In [ ]:
count_atomic_variables(total_req_inputs["Identifier"].unique(),
                       new_core.data_catalog,
                       "labels",
                       ["TableData",
                        "TableDataColumn",
                        "IndexTable",
                        "LineTable",
                        "LineTableColumn",
                        "TimeTable",
                        "TimeTableColumn"])

In [ ]: